package com.botann.projects.model;


import com.botann.projects.annotations.Expand;
import com.botann.projects.annotations.Pass;
import com.botann.projects.annotations.Expand;
import com.botann.projects.annotations.Pass;

import javax.persistence.*;
import java.util.List;

/**
 * cs_erp
 * Menu
 * Created by 刘山国 on 2018/9/28.
 * Copyright (c) 2017 伯坦科技. All rights reserved
 */
@Entity
public class Menu {
    private int id;
    private boolean parent;
    private String url;
    private String menuName;
    private String icon;
    private int level;
    private int menuIndex;
    private int parentId;

    @Pass
    private boolean showing;

    @Pass
    @OneToMany
    private List<View> views;


    // 其他属性,没有setter getter
    @Expand
    @OneToMany
    private List<Menu> children;


    public Menu() {
    }


    public Menu(int id, boolean isParent, String url, String menuName, String icon, int level, int menuIndex, int parentId) {
        this.id = id;
        this.parent = isParent;
        this.url = url;
        this.menuName = menuName;
        this.icon = icon;
        this.level = level;
        this.menuIndex = menuIndex;
        this.parentId = parentId;
    }


    public boolean isShowing() {
        return showing;
    }

    public void setShowing(boolean showing) {
        this.showing = showing;
    }

    public List<View> getViews() {
        return views;
    }

    public void setViews(List<View> views) {
        this.views = views;
    }

    public List<Menu> getChildren() {
        return children;
    }

    public void setChildren(List<Menu> children) {
        this.children = children;
    }

    @Id
    @Column(name = "id", nullable = false)
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Basic
    @Column(name = "parent", nullable = false)
    public boolean isParent() {
        return parent;
    }

    public void setParent(boolean parent) {
        this.parent = parent;
    }

    @Basic
    @Column(name = "url", nullable = false, length = 255)
    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    @Basic
    @Column(name = "menu_name", nullable = false, length = 255)
    public String getMenuName() {
        return menuName;
    }

    public void setMenuName(String menuName) {
        this.menuName = menuName;
    }

    @Basic
    @Column(name = "icon", nullable = false, length = 255)
    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    @Basic
    @Column(name = "level", nullable = false)
    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    @Basic
    @Column(name = "menu_index", nullable = false)
    public int getMenuIndex() {
        return menuIndex;
    }

    public void setMenuIndex(int menuIndex) {
        this.menuIndex = menuIndex;
    }

    @Basic
    @Column(name = "parent_id", nullable = false)
    public int getParentId() {
        return parentId;
    }

    public void setParentId(int parentId) {
        this.parentId = parentId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Menu menu = (Menu) o;

        if (id != menu.id) return false;
        if (parent != menu.parent) return false;
        if (level != menu.level) return false;
        if (menuIndex != menu.menuIndex) return false;
        if (parentId != menu.parentId) return false;
        if (url != null ? !url.equals(menu.url) : menu.url != null) return false;
        if (menuName != null ? !menuName.equals(menu.menuName) : menu.menuName != null) return false;
        if (icon != null ? !icon.equals(menu.icon) : menu.icon != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (parent ? 1 : 0);
        result = 31 * result + (url != null ? url.hashCode() : 0);
        result = 31 * result + (menuName != null ? menuName.hashCode() : 0);
        result = 31 * result + (icon != null ? icon.hashCode() : 0);
        result = 31 * result + level;
        result = 31 * result + menuIndex;
        result = 31 * result + parentId;
        return result;
    }
}
